home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * © Copyright 1994, Apple Computer, Inc.
- *
- * by Rob Glanville
- *
- * 31 Mar 94
- *
- * Hardware.c - Hardware interface for PCI compliance tests
- *
- */
-
- #define UInt8 unsigned char
- #define UInt16 unsigned short
- #define UInt32 unsigned long
- #define PInt8 *(UInt8 *) /* Used for physical address casting */
- #define PInt16 *(UInt16 *) /* Used for physical address casting */
- #define PInt32 *(UInt32 *) /* Used for physical address casting */
- #define True 0xffffffff
- #define False 0x00000000
- #define Null False /* Nothing but trouble */
- #define CR 0x0d
- #define LF 0x0a
-
- extern UInt8 Int8Read (UInt32);
- extern UInt16 Int16Read (UInt32);
- extern UInt32 Int32Read (UInt32);
- extern void Int8Write (UInt32,UInt8);
- extern void Int16Write(UInt32,UInt16);
- extern void Int32Write(UInt32,UInt32);
- extern void printstr(const char *);
- extern void outchar(UInt8);
- extern void byteout(UInt8);
- extern void wordout(UInt16);
- extern void longout(UInt32);
- extern void crlf();
- extern void LineIn();
- extern void Upper(UInt8 *);
- extern void ScanDelimiters();
- extern void getarg();
- extern UInt16 GetValue();
- extern UInt16 PeekMemory();
- extern UInt16 DisplayMemory();
- extern UInt16 FillMemory();
- extern void SyntaxError();
-
- extern UInt8 CommandLine[256]; /* Input buffer */
- extern UInt8 delimiter; /* Delimiter between arguments */
- extern UInt8 AsciiBuf[19]; /* A buffer for output */
- extern UInt8 Argument[0x80]; /* The arguments go here one by one */
- extern UInt8 TabSize; /* Size of tab stops */
-
- extern UInt16 ArgSize; /* Argument size */
- extern UInt16 CPointer; /* Command pointer */
-
- extern UInt32 CommandIndex; /* The index into command buffer */
- extern UInt32 number; /* A place for all numbers input */
- extern UInt32 BufPtr; /* Alias buffer pointer for unions */
- extern UInt32 Base; /* Base address for all accesses */
- extern UInt32 Offset; /* Offset address for some accesses */
- extern UInt32 accessMethod; /* Type of hardware access */
-
- #ifdef OSCode
- #define BanditBase 0xf2000000
- #define BoardReg 0xF301a000
- #endif
-
- #ifdef NativeCode
- #define BanditBase 0xf2000000
- #define BoardReg 0x9001a000
- #endif
-
- /* PCI 0 device selections */
- #define BlueFish (1 << 11)
- #define BlueFish1 (1 << 12)
- #define Jivi (1 << 13)
- #define Gotham (1 << 14)
-
- /* PCI 1 device selections */
- #define BanditDev (1 << 11)
- #define BanditDev1 (1 << 12)
- #define ESlotADev (1 << 13)
- #define ESlotBDev (1 << 14)
- #define ESlotCDev (1 << 15)
- #define GrandCDev (1 << 16)
- #define PCIOptDev (1 << 17)
-
- /* Configuation registers */
- #define DeviceID 0x00
- #define ConfigAdr 0x40
- #define AddressMask 0x48
- #define ModeSelect 0x58
-
- #define PCI1Select 0x00000800
- #define Slot_A_Select 0x00002000
- #define Index_A 0x00
- #define Index_B 0x01
- #define Index_C 0x02
-
- /* Configuration space register offsets */
- #define PCI_VendorID 0x0000
- #define PCI_DeviceID 0x0002
- #define PCI_Command 0x0004
- #define PCI_Status 0x0006
- #define PCI_RevisionID 0x0008
- #define PCI_ClassCode 0x0009
- #define PCI_CacheLineSize 0x000c
- #define PCI_LatencyTimer 0x000d
- #define PCI_HeaderType 0x000e
- #define PCI_BIST 0x000f
- #define PCI_BaseAddress0 0x0010
- #define PCI_BaseAddress1 0x0014
- #define PCI_BaseAddress2 0x0018
- #define PCI_BaseAddress3 0x001c
- #define PCI_BaseAddress4 0x0020
- #define PCI_BaseAddress5 0x0024
- #define PCI_ExpansionROM 0x0030
- #define PCI_InterruptLine 0x003c
- #define PCI_InterruptPin 0x003d
- #define PCI_Min_Gnt 0x003e
- #define PCI_Max_Lat 0x003f
-
- #define GrandCentral 0x90000000
- #define Slot_A 0xe0000000
- #define Slot_B 0xB0000000
- #define Slot_C 0xC0000000
- #define SlotUnderTest ESlotBDev /* Slot B for now */
-
- #define PCI1Address (BanditBase + 0x800000)
- #define PCI1Data (BanditBase + 0xc00000)
-
- #define CPUID 0xf8000000
-
- /**************************************** Utilities **************************************/
-
-
- UInt8 HackFlag;
- void BanditBug() {
- UInt32 ByteBucket;
- ByteBucket = PInt32 CPUID;
- ByteBucket = PInt32 CPUID;
- }
-
- UInt32 ReverseLong(Value) UInt32 Value; {
- UInt32 Temp;
- Temp = (( Value & 0x000000ff) << 24);
- Temp += (((Value >> 8) & 0x000000ff) << 16);
- Temp += (((Value >> 16) & 0x000000ff) << 8);
- Temp += (( Value >> 24) & 0x000000ff);
- return(Temp);
- }
-
- UInt16 ReverseShort(Value) UInt16 Value; {
- UInt16 Temp;
- Temp = ((Value & 0x00ff) << 8);
- Temp += ((Value >> 8) & 0x00ff);
- return(Temp);
- }
-
- UInt8 Read8_Config(Address)
- UInt32 Address;
- {
- UInt8 Data;
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Data =Int8Read(PCI1Data);
- BanditBug();
- return(Data);
- }
-
- void Write8_Config(Address,Data)
- UInt32 Address; UInt8 Data;
- {
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Int8Write(PCI1Data , Data);
- BanditBug();
- }
-
- UInt16 Read16_Config(Address)
- UInt32 Address;
- {
- UInt16 Data;
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Data = ReverseShort(Int16Read(PCI1Data));
- BanditBug();
- return(Data);
- }
-
- void Write16_Config(Address,Data)
- UInt32 Address; UInt16 Data;
- {
- BanditBug();
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Int16Write(PCI1Data , ReverseShort(Data));
- }
-
- UInt32 Read32_Config(Address)
- UInt32 Address;
- {
- UInt32 Data;
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Data =ReverseLong(Int32Read(PCI1Data));
- BanditBug();
- return(Data);
- }
-
- void Write32_Config(Address,Data)
- UInt32 Address,Data;
- {
- Int32Write(PCI1Address , ReverseLong(SlotUnderTest + Address));
- BanditBug();
- Int32Write(PCI1Data , ReverseLong(Data));
- BanditBug();
- }
-
- void InitializeBandit() {
- /* Set up bandit for 0x90000000, 0xA0000000, 0xB0000000, & 0xC0000000 */
- Write32_Config(BanditDev ,AddressMask+PCI1Select ,0x1e0000c);
-
- /* Set Grand Central base address */
- Write32_Config(GrandCDev ,PCI_BaseAddress0 ,GrandCentral);
- Write32_Config(GrandCDev ,PCI_Command ,0x00000016);
- }
-
- void InitializeSlot_A() {
- Write32_Config(ESlotADev ,PCI_Command ,0x00000080);
- Write32_Config(ESlotADev ,PCI_BaseAddress0 ,Slot_A);
- Write32_Config(ESlotADev ,PCI_BaseAddress1 ,0x00009001);
- Write32_Config(ESlotADev ,PCI_Command ,0x00000003);
- }
-
- void InitializeSlot_B() {
- Write32_Config(ESlotBDev ,PCI_Command ,0x00000080);
- Write32_Config(ESlotBDev ,PCI_BaseAddress0 ,0x00000331);
- /* Write32_Config(ESlotBDev ,PCI_BaseAddress0 ,Slot_B); */
- Write32_Config(ESlotBDev ,PCI_Command ,0x0000007);
- }
-
- void InitializeSlot_C() {
- Write32_Config(ESlotCDev ,PCI_BaseAddress0 ,Slot_C);
- Write32_Config(ESlotCDev ,PCI_Command ,0x00000013);
- }
-
- /* Read presents bits for slot b only, Slot under test */
- UInt8 GetPresentsBits() {
- return(((PInt8 BoardReg) >> 2) & 0x03);
- }